from django.template import Library
from django.urls import reverse
from web import models

register = Library()


@register.inclusion_tag('inclusion/all_project.html')
def all_project_list(request):
    my_project_list = models.Project.objects.filter(creator=request.tracer.user)
    join_project_list = models.ProjectUser.objects.filter(user=request.tracer.user)
    return {'my': my_project_list, 'join': join_project_list}


@register.inclusion_tag('inclusion/currrent_menu.html')
def currrent_menu(request):
    data_list = [
        {'title': '概览', 'url': reverse("dashboard", kwargs={'project_id': request.tracer.project.id})},
        {'title': '问题', 'url': reverse("issues", kwargs={'project_id': request.tracer.project.id})},
        {'title': '统计', 'url': reverse("statistics", kwargs={'project_id': request.tracer.project.id})},
        {'title': 'wiki', 'url': reverse("wiki", kwargs={'project_id': request.tracer.project.id})},
        {'title': '文件', 'url': reverse("files", kwargs={'project_id': request.tracer.project.id})},
        {'title': '设置', 'url': reverse("settings", kwargs={'project_id': request.tracer.project.id})},
    ]
    for item in data_list:
        # 当前用户访问的URL：request.path_info:/manage/3/dashboard/xxx/add/
        if request.path_info.startswith(item['url']):
            item['class'] = 'active'
    return {'data_list': data_list}
